from Data import search_file
import win32com.client
import os


def test():
    filepaths = search_file.select_file()
    for filepath in filepaths:
        word = win32com.client.DispatchEx("Word.Application")
        word.Visible = True
        word.DisplayAlerts = False
        doc = word.Documents.Open(os.path.abspath(filepath))
    
        # 遍历100-200个段落
        for i in range(50, min(150, doc.Paragraphs.Count)):
            text = doc.Paragraphs[i].Range.Text.strip()
            if text:  # 只输出非空段落
                print(f"段落 {i+1}: {text}")

        # 关闭文档和Word应用
        doc.Close(SaveChanges=False)
        word.Quit()
        del word

if __name__ == '__main__':
    test()
